#[derive(Debug)]
struct Rectangle {
    width: u32,
    height: u32,
} 

impl Rectangle {
    fn area(&self) -> u32 {
        self.height * self.width
    }
}

// 关联方法
impl Rectangle {
    fn square(size:u32) -> Rectangle {
        Rectangle {
            width : size,
            height : size,
        }
    }
}

fn main() {
    let mut rectangle = Rectangle{
        width : 10,
        height : 20,
    };

    println!("rectangle is {:#?}", rectangle);
    println!("rectangle's area is {}",rectangle.area());

    rectangle.width = 20;

    println!("rectangle is {:#?}", rectangle);
    println!("rectangle's area is {}",rectangle.area());

    print_area(rectangle);

    // rectangle.area();

    let square = Rectangle::square(10);

    println!("rectangle is {:#?}", square);
}

fn print_area(r :Rectangle){
    println!("rectangle's area is {}",r.area());
}